from django import forms
from blog.models import Comment


class CommentForm(forms.ModelForm):
    class Meta:
        model = Comment
        # 需要呈现在页面上的表单元素
        fields = ["name", "email", "content"]
        # 定义字段对应的表单元素以及属性
        widgets = {
            # id 是为了方便jquery获取元素的属性和值
            # class 用来调用bootstrap中的样式
            "name": forms.TextInput(attrs={"id": "name", "class": "form-control",
                                           "placeholder": "请输入昵称"}),
            "email": forms.EmailInput(attrs={"id": "email", "class": "form-control",
                                             "placeholder": "请输入邮箱"}),
            "content": forms.Textarea(attrs={"id": "content", "class": "form-control",
                                             "placeholder": "请输入评论内容"})
        }
